package org.inspursc.s0517.health.evaluation.utils;


import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * @author B_Dream
 * @date 2018/5/29 16:12
 */
public class TimeUtil {

    public static LocalDate toDateToLocalDate(Date date) {
        if (date != null) {
            Instant instant = date.toInstant();
            ZoneId zone = ZoneId.systemDefault();
            LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zone);
            LocalDate localDate = localDateTime.toLocalDate();
            return localDate;
        } else {
            return null;
        }
    }

    public static Date toLocalDateToDate(LocalDate localDate) {
        if (localDate != null) {
            ZoneId zone = ZoneId.systemDefault();
            Instant instant = localDate.atStartOfDay().atZone(zone).toInstant();
            java.util.Date date = Date.from(instant);
            return date;
        } else {
            return null;
        }
    }

}
